package com.boke.order.dao;

import com.boke.order.pojo.Order;
import com.boke.order.pojo.Orders;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.PathVariable;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import java.util.Map;

/* ━━━━━━佛祖保佑━━━━━━
 *                  ,;,,;
 *                ,;;'(    社
 *      __      ,;;' ' \   会
 *   /'  '\'~~'~' \ /'\.)  主
 * ,;(      )    /  |.     义
 *,;' \    /-.,,(   ) \    码
 *     ) /       ) / )|    农
 *     ||        ||  \)
 *     (_\       (_\
 * ━━━━━━永无BUG━━━━━━
 * @author ：zjq
 * @date ：2020/7/28 14:31
 * @description: TODO
 * @version: V1.0
 * @slogan: 天下风云出我辈，一入代码岁月催
 */
public interface OrderDao {


    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert("INSERT INTO t_order (id, name, create_time,user_name) VALUES (#{id}," +
            " #{name}, #{createTime},#{userName})")
    long inserto(Order order);

    @Select("SELECT * FROM t_order limit #{offset},#{size}")
    List<Orders> selectRangePage(@Param("offset") int offset, @Param("size") int size);

    @Select("select * from t_order where order_id=#{orderId}")
    Orders selectByOrderId(@PathVariable("orderId") long orderId);

    @Select("select * from t_order where user_id >= #{userId}")
    List<Orders>  selectRangeByUserId(@PathVariable("userId") int userId);

    @Select("select * from t_order where  DATE_FORMAT(create_time,'%Y-%m-%d')=#{time}")
    List<Orders> selectByDate(@PathVariable("time") String time);

    //====================================================================================================//

    @Options(useGeneratedKeys = true, keyProperty = "orderId", keyColumn = "order_id")
    @Insert("INSERT INTO t_order (user_id, address_id, status,create_time) VALUES (#{userId}," +
            " #{addressId}, #{status},#{createTime})")
    long insert(Orders order);

    @Delete("DELETE FROM t_order WHERE order_id = #{orderId}")
    void delete(long orderId) throws SQLException;


    List<Map<String, Object>> selectAll() throws SQLException;

    @Select("SELECT * FROM t_order WHERE order_id BETWEEN #{start} AND #{end}")
    List<Orders> selectRange(@Param("start") int start, @Param("end") int end) throws SQLException;

    @Select("SELECT * FROM t_order order by order_id limit #{offset},#{size}")
    List<Orders> selectPageList(@Param("offset") long offset, @Param("size") long size) throws SQLException;

    @Update("update t_order set status = #{status} where order_id = #{orderId}")
    int update(@Param("orderId") long orderId, @Param("status") String status) throws SQLException;


}
